GetEventsByPeriodQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 26
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 23 2
1
import { Inject } from '@nestjs/common';
2
import { QueryHandler } from '@nestjs/cqrs';
3
import { GetEventsByPeriodQuery } from './GetEventsByPeriodQuery';
4
import { IEventRepository } from 'src/Domain/Calendar/Repository/IEventRepository';
5
import { EventView } from '../View/EventView';
6
7
@QueryHandler(GetEventsByPeriodQuery)
8
export class GetEventsByPeriodQueryHandler {
9
  constructor(
10
    @Inject('IEventRepository')
11
    private readonly eventRepository: IEventRepository
12
  ) {}
13
14
  public async execute(query: GetEventsByPeriodQuery): Promise<EventView[]> {
15
    const { fromDate, toDate } = query;
16
    const eventViews: EventView[] = [];
17
    const events = await this.eventRepository.findByPeriod(fromDate, toDate);
18
19
    for (const event of events) {
20
      const user = event.getPhotographer();
21
      const school = event.getSchool();
22
      const schoolInformation = `${school.getName()} - ${school.getReference()}`;
23
      const userInformation = `${user.getFirstName()} ${user.getLastName()}`;
24
25
      eventViews.push(
26
        new EventView(
27
          event.getId(),
28
          `[${userInformation}] ${schoolInformation}`,
29
          event.getDate(),
30
          event.getSummary()
31
        )
32
      );
33
    }
34
35
    return eventViews;
36
  }
37
}
38